import {defineStore} from "pinia";
import axios from "axios";
import {computed, ref} from "vue";
import useCityStoreStore from "./cityStore.js";

const cityStore = useCityStoreStore()

//第一个参数是唯一storeId
const useCinemaStore = defineStore("cinema",()=>{
    const cinemaList =ref([])
    const getCinemaList = async ()=>{
        let res = await axios({
            url: `https://m.maizuo.com/gateway?cityId=${cityStore.cityId}&ticketFlag=1&k=7147275`,
            headers: {
                'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"1700982879663830145269761"}',
                'X-Host': 'mall.film-ticket.cinema.list',
            }
        })
        cinemaList.value =  res.data.data.cinemas
    }
    const filterCinemaList = computed(()=>
        (type)=> {
            return cinemaList.value.filter(item => item.eTicketFlag === type)
        }
    )

    const cleanCinemaList = () =>{
        cinemaList.value = []
    }


    return {
        cinemaList,
        getCinemaList,
        filterCinemaList,
        cleanCinemaList
    }


})

export default useCinemaStore